﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using HPIT_Library;
using HPIT_Library_Modal;

namespace HPIT_Library_DAL
{
    public class LoginSerivers
    {
        public static LoginInfo Login(string name, string pwd)
        {
            //sql语句
            string sql = "select * from [Login] where useName=@useName and password=@password";
            SqlParameter[] pams = { 
                new SqlParameter("@useName",name),
                new SqlParameter("@password",pwd),
            };
            SqlDataReader reader=DbHelper.ExecuteReader(sql, pams);
            LoginInfo login = null;
            if (reader.Read())
            {
                login = new LoginInfo()
                { 
                    useName=Convert.ToString(reader["useName"]),
                    id = Convert.ToInt32(reader["id"]),
                    password = Convert.ToString(reader["password"]),

                };
            }
            reader.Close();
            return login;
        }
        public static int UpdatePwd(string password,int id)
        {
            string sql = "update Login set password=@password where id=@id";
            SqlParameter[] pams = { 
            new SqlParameter("@password",password),
            new SqlParameter("@id",id)
            };
            return DbHelper.ExecuteNonQuery(sql, pams);
      
        }
    }
}
